* This do-file reproduces the analyses in Online Appendix A2 for the article ///
* "The Behavioral Immune System Shapes Political Intuitions: Why and How Individual ///
* Differences in Disgust Sensitivity Underlie Opposition to Immigration" by Lene Aarøe, Michael Bang Petersen & Kevin Arceneaux
* The do-file is intended to be used on the .dta-file, "Replication Data Meta-Analysis"


* Note on the replication data set: The main set of analyses in Online Appendix A2 focus on the empirical evidence for the basic prediction ///
* of the direct relationship between the behavioral immune system and opposition to immigration. Furthermore, Figure A2 report the identified ///
* hypothesized interactions in the 16 articles focusing on the conditionality of the effect of behavioral immune sensitivity  on opposition to immigration.
* As the wording of these interaction hypotheses is the only coding/finding we report from the interaction analyses in the published literature ///
* the replication dataset includes no coded information on the type of research design, statistical analysis and statistical results for ///
* these interaction analyses in the published literature (i.e. observations with the value "1" on the variable "interaction”).”

*************
* RECODINGS *
*************

* Generation of variable that identifies whether the test is part of the main sample or the inclusive sample in the analyses ///
* if the evidence for the direct relationship between the behavioral immune system and opposition to immigration

gen Main=Primary
replace Main=1 if Researchdesign==1
replace Main=. if Interaction==1

************
* ANALYSES *
************

* Note that the published figures (except Figure A1H and Figure A2H) are created in Excel on the basis of the data generated by the below analyses
* Commands for generating corresponding graphs are included in this file for illustrative purposes

*******************************************
* Analyses for Online Appendix A2.1. *
*******************************************

* How many studies find a significant association between behavioral immune sensitivity and opposition towards immigrants? (result reported in text in A2.1, main sample/main analysis)

gen significant =.
replace significant = 1 if  Pvalue < 0.05
replace significant = 1 if  Pvalue == 0.05
replace significant = 0 if  Pvalue > 0.05 & Pvalue < 1
replace significant = 1 if  Pvalue == 100
replace significant = 1 if  Pvalue == 105
replace significant = 1 if  Pvalue == 110
replace significant = 1 if  Pvalue == 111
replace significant = 0 if  Pvalue == 200
replace significant = . if  Pvalue ==.
label define significant 0 "non-significant" 1 "significant"
label values significant significant

ta significant if Main==1 & Interaction==0

* What is the mean effect size? (result reported in text in A2.1, main sample/main analysis)
* Note that only r and standardized betas are reported in this analysis

gen ResultRC=Result
replace ResultRC=-Result if Inversecoded==1 & Interaction==0 

sum ResultRC if Main == 1 & Inferred !=1 & Statistic < 3 & Interaction==0

* Generation of data for Figure A1A

gen ResultRCint=.
replace ResultRCint=0 if ResultRC >= -.25 & ResultRC < -.20 & Statistic < 3
replace ResultRCint =1 if ResultRC >= -.20 & ResultRC < -.15 & Statistic < 3
replace ResultRCint =2 if ResultRC >= -.15 & ResultRC < -.10 & Statistic < 3
replace ResultRCint =3 if ResultRC >= -.10 & ResultRC < -.05 & Statistic < 3
replace ResultRCint =4 if ResultRC >= -.05 & ResultRC < 0 & Statistic < 3
replace ResultRCint =5 if ResultRC >= 0 & ResultRC < .05 & Statistic < 3
replace ResultRCint =6 if ResultRC >= .05 & ResultRC < .10 & Statistic < 3
replace ResultRCint =7 if ResultRC >= .10 & ResultRC < .15 & Statistic < 3
replace ResultRCint =8 if ResultRC >= .15 & ResultRC < .20 & Statistic < 3
replace ResultRCint =9 if ResultRC >= .20 & ResultRC < .25 & Statistic < 3
replace ResultRCint =10 if ResultRC >= .25 & ResultRC < .30 & Statistic < 3
replace ResultRCint =11 if ResultRC >= .30 & ResultRC < .35 & Statistic < 3
replace ResultRCint =12 if ResultRC >= .35 & ResultRC < .40 & Statistic < 3
replace ResultRCint =13 if ResultRC >= .40 & ResultRC < .45 & Statistic < 3
replace ResultRCint =14 if ResultRC >= .45 & ResultRC < .50 & Statistic < 3
replace ResultRCint =15 if ResultRC >= .50 & ResultRC < .55 & Statistic < 3

label define result 0 "-.25 - -.21" 1 "-.20 - -.16" 2 "-.15 - -.11" 3 "-.10 - -.6" 4 "-.5 - -.1" 5 "0 - .4" 6 ".5 - .9" 7 ".10 - .14" ///
8 ".15 - .19" 9 ".20 - .24" 10 ".25 - .29" 11 ".30 - .34" 12 ".35 - .39" 13 ".40 - .44" 14 ".45 - .49" 15 ".50 - .54"
label val ResultRCint result

ta ResultRCint if Main==1 & Inferred!=1 & Interaction==0

* Illustrative graph for Figure A1A

graph bar if Main==1 & Inferred!=1 & Interaction==0, over(ResultRCint) allc title("A1A. Effect Size (N = 56)")  ///
yscale(range(0 24)) ///
ylabel(0(4)24,nogrid) ///   	
ytitle("Percent") ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  	 

* Generation of data for Figure A1B

gen Samplesizeint=.
replace Samplesizeint = 0 if Samplesize > 0 & Samplesize <51
replace Samplesizeint = 1 if Samplesize >= 51 & Samplesize <101
replace Samplesizeint = 2 if Samplesize >= 101 & Samplesize <151
replace Samplesizeint = 3 if Samplesize >= 151 & Samplesize <201
replace Samplesizeint = 4 if Samplesize >= 201 & Samplesize <251
replace Samplesizeint = 5 if Samplesize >= 251 & Samplesize <301
replace Samplesizeint = 6 if Samplesize >=301 & Samplesize <351
replace Samplesizeint = 7 if Samplesize >= 351 & Samplesize <401
replace Samplesizeint = 8 if Samplesize >= 401 & Samplesize <451
replace Samplesizeint = 9 if Samplesize >= 451 & Samplesize <501

label define sample 0 "0 - 50" 1 "51 - 100" 2 "101 - 150" 3 "151 - 200" 4 "201 - 250" 5 "251 - 300" 6 "301 - 350" 7 "351 - 400" ///
8 "401 - 450" 9 "451 - 500"
label val Samplesizeint sample

ta Samplesizeint if Main==1 & Interaction==0

* Illustrative graph for Figure A1B

graph bar if Main==1 & Interaction==0, over(Samplesizeint) blabel(bar) allc title("A1B. Sample Size (N = 68)")  ///
yscale(range(0 40)) ///
ylabel(0(10)40,nogrid) ///   	
ytitle("Percent") ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  	 

* Identification of the number of underpowered studies (result reported in text in A2.1)

power onecorrelation 0 .2352
ta Samplesize if Main ==1 & Interaction==0
	
* Generation of data for Figure A1C

ta Samplecountry if Main==1 & Interaction==0

* Illustrative graph for Figure A1C

graph bar (count) if Main==1 & Interaction==0, over(Samplecountry) blabel(bar) allc title("A1C. Site of Study (N = 68)")  ///
yscale(range(0 60)) ///
ylabel(0(20)60,nogrid) ///   	
ytitle("Number of results") ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  
	
* Generation of data for Figure A1D

ta Typeofsample if Main==1 & Interaction==0

* Illustrative graph for Figure A1D

graph bar if Main==1 & Interaction==0, over(Typeofsample) blabel(bar) allc title("A1D. Type of Sample (N = 68)")  ///
yscale(range(0 100)) ///
ylabel(0(20)100,nogrid) ///   	
ytitle("Percent") ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  

* Generation of data for Figure A1E

ta Researchdesign if Main==1 & Interaction==0

* Illustrateive graph for Figure A1E

graph bar (count) if Main==1 & Interaction==0, over(Researchdesign) blabel(bar) allc title("A1E. Site of Study (N = 68)")  ///
yscale(range(0 40)) ///
ylabel(0(10)40,nogrid) ///   	
ytitle("Number of results") ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  
	
* Generation of data for Figure A1F

ta Control if Main==1 & Interaction==0

* Illustrative graph for Figure A1F

graph bar (count) if Main==1 & Interaction==0, over(Control) blabel(bar) allc title("A1F. Control for Education and Income (N = 68)")  ///
yscale(range(0 80)) ///
ylabel(0(20)80,nogrid) ///   	
ytitle("Number of results") ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  
	
* Generation of Figure A1G

* Generation of data

bys Samplesize: ta ResultRC if Main == 1 & Inferred !=1 & Statistic < 3 & Interaction==0

* On this basis the following code is written and pasted into the form available at http://p-curve.com/ (p curve app 4.05)///
** our results where checked the final time 11 January 2017 in version 4.05 of the App.

r(45)=.24

r(47)=-.03
r(47)=.22
r(47)=.25
r(47)=.25
r(47)=.29
r(47)=.3
r(47)=.34
r(47)=.36
r(47)=.38
r(47)=.48
r(47)=.53

r(52)=.05
r(52)=.24


r(82)=.13
r(82)=.14
r(82)=.21
r(82)=.22
r(82)=.31
r(82)=.33


r(86)=.22
r(86)=.38

r(88)=.37

r(90)=.23

r(103)=.14
r(103)=.25
r(103)=.25
r(103)=.33

r(119)=.05
r(119)=.18
r(119)=.23
r(119)=.33

r(126)=.11
r(126)=.24

r(135)=.29
r(135)=.3
r(135)=.34
r(135)=.40

r(146)=.15

r(206)=.13
r(206)=.28
r(206)=.29
r(206)=.31
r(206)=.34


r(225)=-.08
r(225)=-.08
r(225)=.43

r(249)=.11

r(331)=.1
r(331)=.14

r(412)=.07
r(412)=.19
r(412)=.21
r(412)=.23


* Generation of Figure A1H

* Location of mean effect size

sum ResultRC if Main == 1 & Inferred !=1 & Statistic < 3 & Interaction==0

* Generation of variable that measures the deviation from the mean

gen DeviationMean = ResultRC -.2352 if Main == 1 & Inferred !=1 & Statistic < 3 & Interaction==0 

* Generation of Figure A1H
	
twoway (scatter Samplesize DeviationMean), title("") ytitle("Sample size") xtitle("Deviation from mean effect size") xline(0, lpattern (dash) lcolor(black)) /// 	
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  
sum Samplesize if DeviationMean !=.

* Correlation between deviation from mean effect size and sample size (result reported in text in A2.1)

pwcorr DeviationMean Samplesize if Main==1 & Interaction==0, obs sig 	
	
* Number and content of interaction hypotheses (Figure 2 in Online Appendix A2.1)
** Stata 12 (the format of the replication data set) only allows a maximum length of str244 for string variables ///
**Therefore the wording of three interaction hypotheses is shortened when saving the replication data set in Stata 12 format///
** Therefore we also include the replication data for the meta-analysis as an excel file. Please consult the .csv-file,///
** "Replication Data Meta-Analysis Excel Format" to see the full wording of all interaction hypotheses. 

browse Hypothesis

* Sample size of interaction tests

bys Samplesize: ta Hypothesis

****************************************
* Analyses for Online Appendix A2.2. *
*****************************************

* How many studies find a significant association between the preferred BIS measure and opposition towards immigrants? (result reported in text in A2.2)

ta significant if Interaction==0 

* What is the mean effect size? (result reported in text in A2.2)
* Note that only r and standardized betas are reported in this analysis

sum ResultRC if Inferred !=1 & Statistic < 3 & Interaction==0

* Generation of data for Figure A3A

ta ResultRCint if Inferred!=1 & Statistic < 3 & Interaction==0

* Illustrative graph for Figure A3A

graph bar if Inferred!=1 & Interaction==0, over(ResultRCint) allc title("A3A. Effect Size (N = 85)")  ///
yscale(range(0 24)) ///
ylabel(0(4)24,nogrid) ///   	
ytitle("Percent") ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  	 

* Generation of data for Figure A3B

ta Samplesizeint if Interaction==0

* Illustrative graph for Figure A3B

graph bar if Interaction==0, over(Samplesizeint) blabel(bar) allc title("A3B. Sample Size (N = 99)")  ///
yscale(range(0 40)) ///
ylabel(0(10)40,nogrid) ///   	
ytitle("Percent") ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  	 

* Generation of data for Figure A3C

ta Samplecountry if Interaction==0

* Illustrative graph for Figure A3C

graph bar (count) if Interaction==0, over(Samplecountry) blabel(bar) allc title("A3C. Site of Study (N = 99)")  ///
yscale(range(0 60)) ///
ylabel(0(20)60,nogrid) ///   	
ytitle("Number of results") ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  
	
* Generation of data for Figure A3D

ta Typeofsample if Interaction==0

* Illustrative graph for Figure A3D

graph bar if Interaction==0, over(Typeofsample) blabel(bar) allc title("A3D. Type of Sample (N = 99)")  ///
yscale(range(0 100)) ///
ylabel(0(20)100,nogrid) ///   	
ytitle("Percent") ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  

* Generation of data for Figure A3E

ta Researchdesign if Interaction==0

* Illustrateive graph for Figure A3E

graph bar (count) if Interaction==0, over(Researchdesign) blabel(bar) allc title("A3E. Site of Study (N = 99)")  ///
yscale(range(0 40)) ///
ylabel(0(10)40,nogrid) ///   	
ytitle("Number of results") ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  
	
* Generation of data for Figure A3F

ta Control if Interaction==0

* Illustrative graph for Figure A3F

graph bar (count) if Interaction==0, over(Control) blabel(bar) allc title("A3F. Control for Education and Income (N = 99)")  ///
yscale(range(0 80)) ///
ylabel(0(20)80,nogrid) ///   	
ytitle("Number of results") ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  
	
* Generation of Figure A3G

* Generation of data

bys Samplesize: ta ResultRC if Interaction == 0 & Inferred !=1 & Statistic < 3 & Interaction==0
sum ResultRC if Interaction == 0 & Inferred !=1 & Statistic < 3 & Samplesize !=. & Interaction==0

* On this basis the following code is written and pasted into the form available at http://p-curve.com/

r(45)=.24

r(47)=-.03
r(47)=.22
r(47)=.25
r(47)=.25
r(47)=.29
r(47)=.3
r(47)=.34
r(47)=.36
r(47)=.38
r(47)=.48
r(47)=.53

r(52)=.05
r(52)=.24

r(82)=.13
r(82)=.14
r(82)=.21
r(82)=.22
r(82)=.31
r(82)=.33

r(86)=.22
r(86)=.38

r(88)=.37

r(90)=.23

r(103)=-.19
r(103)=-.17
r(103)=-.14
r(103)=-.03
r(103)=-.01
r(103)=0
r(103)=.08
r(103)=.14
r(103)=.25
r(103)=.25
r(103)=.33

r(119)=.05
r(119)=.09
r(119)=.09
r(119)=.15
r(119)=.15
r(119)=.18
r(119)=.23
r(119)=.33

r(126)=.11
r(126)=.24

r(135)=-.22
r(135)=-.18
r(135)=.-12
r(135)=-.09
r(135)=.19
r(135)=.26
r(135)=.27
r(135)=.27
r(135)=.29
r(135)=.3
r(135)=.34
r(135)=.40

r(146)=.15

r(206)=-.17
r(206)=-.15
r(206)=-.13
r(206)=-.11
r(206)=-.06
r(206)=-.06
r(206)=-.02
r(206)=-.02
r(206)=.13
r(206)=.28
r(206)=.29
r(206)=.31
r(206)=.34

r(225)=-.08
r(225)=-.08
r(225)=.43

r(249)=.11
r(249)=.17

r(331)=.10
r(331)=.14

r(412)=.07
r(412)=.19
r(412)=.21
r(412)=.23

* Generation of Figure A3H
*** Note the mislabeling of the figure ***

* Location of mean effect size

sum ResultRC if Interaction == 0 & Inferred !=1 & Statistic < 3 & Interaction==0

* Generation of variable that measures the deviation from the mean

gen DeviationMean2 = ResultRC -.1530 if Interaction == 0 & Inferred !=1 & Statistic < 3 & Interaction==0

* Generation of Figure A3H
	
twoway (scatter Samplesize DeviationMean2), title("") ytitle("Sample size") xtitle("Deviation from mean effect size") xline(0, lpattern (dash) lcolor(black)) /// 	
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))  

* Correlation between deviation from mean effect size and sample size (result reported in text in A2.2)

pwcorr DeviationMean2 Samplesize if Interaction==0 , obs sig 	
